package com.magic.smartcity.view.me;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;

import com.magic.smartcity.beans.BalanceBean;
import com.magic.smartcity.beans.FeedbackBean;
import com.magic.smartcity.beans.UserBean;
import com.magic.smartcity.databinding.FragmentMeRegisterBinding;
import com.magic.smartcity.interfaces.IUserCallBack;
import com.magic.smartcity.interfaces.IUserPresenter;
import com.magic.smartcity.interfaces.base.BaseUserCallBackFragment;

import java.util.List;

import javax.inject.Inject;

import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class MeRegisterFragment extends BaseUserCallBackFragment {

    private FragmentMeRegisterBinding mBinding;

    @Inject
    IUserPresenter mUserPresenter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = FragmentMeRegisterBinding.inflate(getLayoutInflater());
        mUserPresenter.registerCallBack(this);

        mBinding.register.setOnClickListener(v -> {
            mUserPresenter.registerUser(mBinding.username.getText().toString(),
                    mBinding.password.getText().toString(),
                    mBinding.phonenumber.getText().toString());
        });

        return mBinding.getRoot();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mUserPresenter.unRegisterCallBack(this);
    }


    @Override
    public void registerOk(String token) {
        Toast.makeText(getActivity().getBaseContext(), token, Toast.LENGTH_SHORT).show();
        Navigation.findNavController(mBinding.getRoot()).popBackStack();
    }

    @Override
    public void error(String str) {
        Toast.makeText(getActivity().getBaseContext(), str, Toast.LENGTH_SHORT).show();
    }

}